package com.itita.ww2.model.item.prop;

import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.enums.WW2ExceptionCode;
import com.itita.ww2.model.item.AbstractItem;
import com.itita.ww2.model.item.enums.ItemPropType;
import com.itita.ww2.model.item.interfaces.IUseable;
import com.itita.ww2.model.user.UserProfile;
import com.smartfoxserver.v2.entities.data.ISFSObject;

public class ItemProp extends AbstractItem {
	private ItemPropType propType;
	// 
	private Object effValue;
	//
	private IUseable usedStrategy;

	public ItemProp(String itemId, int param1, int param2, boolean useable, int effParam, Object effValue,
			boolean compositable) {
		super(itemId, param1, param2, useable, effParam);
		this.propType = ItemPropType.idValueOf(itemId);
		this.effValue = effValue;
		this.compositable = compositable;
		// 设置具体执行策略
		setUsedStrategy();
	}

	private void setUsedStrategy() {
		switch (propType) {
		case EXP:
			usedStrategy = new ExpPropStrategy(this);
			break;
		case FUNCTION:
			usedStrategy = new FunctionPropStrategy(this);
			break;
		case CHEST:
			usedStrategy = new ChestPropStrategy(this);
			break;
		default:
			break;
		}
	}

	public ISFSObject use(UserProfile userProfile, ISFSObject params)
			throws WW2Exception {
		if (usedStrategy == null) {
			throw new WW2Exception(WW2ExceptionCode.SERVER_ERROR, "UseItem [0x001]");
		}
		return usedStrategy.use(userProfile, params);
	}

	public ItemPropType getPropType() {
		return propType;
	}

	public Object getEffValue() {
		return effValue;
	}

	@Override
	public boolean canStack() {
		return true;
	}
}
